package cn.tedu._06interceptor.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 第一个拦截器
 *  1.实现HandlerInterceptor接口
 *  2.重写3个方法: preHandle, postHandle, afterCompletion
 *  
 */
public class MyInterceptor1 implements HandlerInterceptor {
    /**
     * preHandle:在请求处理之前进行调用(Controller方法调用之前)
     * @param request 请求对象
     * @param response 响应对象
     * @param handler 出方法对象
     * @return true 放行; false 拦截
     * @throws Exception 异常对象
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("1.第一个拦截器preHandle执行");
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("2.第一个拦截器postHandle执行");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("3.第一个拦截器afterCompletion执行");
    }
}
